package com.lostandfound.controller.admin;

import com.lostandfound.pojo.Result;
import com.lostandfound.pojo.User;
import com.lostandfound.service.admin.RegisterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/register")
@Slf4j
public class RegisterController {
    @Autowired
    private RegisterService registerService;
    @PostMapping
    public Result register(@RequestBody User user){

        User user1 = registerService.findByUsername(user.getUserName());
        if (user1 != null){
            return Result.error("用户名已存在");
        }else {
            registerService.register(user);
        }

        return Result.success("注册成功",1);
    }

}
